console.log("==============================================");

import { createApp, ref } from "vue";
import App from "./App.vue";
import NzCzm from "./assets/js/mapjs/nzczm";

import { httpGet } from "./assets/js/HttpUtils";

import ElementPlus from "element-plus";
import "element-plus/theme-chalk/index.css";
import * as icons from "@element-plus/icons-vue";

const app = createApp(App);

for (const [key, component] of Object.entries(icons)) {
  app.component(key, component);
}

Promise.all([httpGet("/public/config/maps.json", {}), httpGet("/public/config/terr.json", {}), httpGet("/public/config/theme.json", {})]).then((arr) => {
  const mapsItem = arr[0].data;
  const terrItem = arr[1].data;
  const themeItem = arr[2].data;

  const config = {
    basemap: mapsItem,
    terrain: terrItem,
    theme: themeItem
  };
  app.provide("config", config);

  let global_vars = {
    basemap: {
      selected_id: 0,
    },
    terrain: {
      selected_id: 0,
      show_bar: false,
      exaggerate_enable: false,
      exaggerate_value: 1.0,
    },
    theme: {
      selected_id: "",
    },
  };

  app.config.globalProperties.global_vars = global_vars;

  var nzczm = new NzCzm();
  app.provide("nzczm", nzczm);

  app.use(ElementPlus).mount("#app");
});
